package com.jzo2o.foundations.controller.operation;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IRegionServeService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author: liZhiJun
 * @CreateTime: 2025-09-24
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("/operation/serve")
@RequiredArgsConstructor
public class RegionServeController {

    private final IRegionServeService regionServeService;

    /**
     * 服务分页查询
     *
     * @param servePageQueryReqDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        Page<ServeResDTO> resDTOPage = regionServeService.page(servePageQueryReqDTO);
        return new PageResult<>(resDTOPage.getPages(), resDTOPage.getTotal(), resDTOPage.getRecords());
    }

    /**
     * 区域服务批量新增
     */
    @PostMapping("/batch")
    @ApiOperation("区域服务批量新增")
    public void batchAdd(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOS) {
        regionServeService.batchSava(serveUpsertReqDTOS);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改价格")
    public void updataPrice(@PathVariable Long id, @RequestParam("price") BigDecimal price) {
        regionServeService.updatePrice(id, price);
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("上架")
    public void onSale(@PathVariable Long id) {
        regionServeService.onSale(id);
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("上架")
    public void offSale(@PathVariable Long id) {
        regionServeService.offSale(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public void delete(@PathVariable Long id) {
        regionServeService.removeById(id);
    }

    @PutMapping("/onHot/{id}")
    @ApiOperation("设置热门")
    public void onHot(@PathVariable Long id) {
        regionServeService.onHot(id);
    }

    @PutMapping("/offHot/{id}")
    @ApiOperation("设置热门")
    public void offHot(@PathVariable Long id) {
        regionServeService.offHot(id);
    }
}
